double mypow(double x, int n) {
    long long exp = n;
    if (exp < 0) {
        x = 1.0 / x;
        exp = -exp;
    }
    if (exp == 0) {
        return 1.0;
    }
    double half = mypow(x, exp / 2);
    if (exp % 2 == 0) {
        return half * half;
    } else {
        return x * half * half;
    }
}